package org.gangcai.mac.shop.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;

import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.GlideEngine;
import com.zhihu.matisse.internal.entity.CaptureStrategy;

import org.gangcai.mac.shop.R;

import java.io.File;
import java.util.List;

/**
 * Created by meijun on 18-1-9.
 */

public class MatisseUtils {

    private static String authority = "org.gangcai.mac.shop.fileprovider";

    public static void pickImage(Activity activity, int maxSelectable, int REQUEST_CODE_CHOOSE) {
        Matisse.from(activity)
                .choose(MimeType.allOf())
                .countable(true)
                .capture(true)
                .captureStrategy(new CaptureStrategy(true, authority))//存储到哪里
                .maxSelectable(maxSelectable)
                // .addFilter(new GifSizeFilter(320, 320, 5 * Filter.K * Filter.K))
                // .gridExpectedSize(getResources().getDimensionPixelSize(R.dimen.grid_expected_size))
                .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
                .thumbnailScale(0.85f)
                .theme(R.style.Zhihu)
                .imageEngine(new GlideEngine())
                .forResult(REQUEST_CODE_CHOOSE);
    }

    public static List<Uri> getImages(Intent data) {
        if (data == null) {
            return null;
        }
        List<Uri> uris = Matisse.obtainResult(data);
        return uris;
    }

    public static File getFile(Uri uri, Context context) {
        String realPathFromURI = UriUtils.getRealPathFromURI(context,uri);
        return new File(realPathFromURI);
    }
}
